package com.lixinxin.commoncomposeproject

import android.os.Bundle
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.activity.viewModels
import androidx.compose.animation.ExperimentalAnimationApi
import androidx.compose.foundation.layout.fillMaxHeight
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.material.MaterialTheme
import androidx.compose.material.Surface
import androidx.compose.material.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.tooling.preview.Preview
import androidx.navigation.compose.NavHost
import androidx.navigation.compose.composable
import androidx.navigation.compose.rememberNavController
import com.google.accompanist.pager.ExperimentalPagerApi
import com.lixinxin.commoncomposeproject.demo.layout.ListViewDemo
import com.lixinxin.commoncomposeproject.demo.layout.RowDemo
import com.lixinxin.commoncomposeproject.demo.util.SampleData
import com.lixinxin.commoncomposeproject.model.ArticleState
import com.lixinxin.commoncomposeproject.repository.CommonData
import com.lixinxin.commoncomposeproject.screen.*
import com.lixinxin.commoncomposeproject.screen.util.Screen
import com.lixinxin.commoncomposeproject.ui.theme.CommonComposeProjectTheme
import com.lixinxin.commoncomposeproject.view.ShimmerAnimate
import com.lixinxin.commoncomposeproject.view_model.ArticleViewModel


@ExperimentalPagerApi
class MainActivity : ComponentActivity() {


    private val articleViewModel: ArticleViewModel by viewModels()

    @ExperimentalAnimationApi
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContent {
            CommonComposeProjectTheme {
                //NavControllerPage()

               // ShimmerAnimate()

                NetworkScreen()

            }
        }
    }
}

@Preview(showBackground = true)
@Composable
fun DefaultPreview() {
    CommonComposeProjectTheme {
        RowDemo("Android")
    }
}


@ExperimentalAnimationApi
@ExperimentalPagerApi
@Composable
fun NavControllerPage() {
    Surface(
        color = MaterialTheme.colors.background,
        modifier = Modifier
            .fillMaxHeight()
            .fillMaxWidth()
    ) {
        val navController = rememberNavController()
        NavHost(
            navController = navController,
            startDestination = Screen.NetworkScreen.route
        ) {
            composable(route = Screen.WelcomeScreen.route) {
                WelcomeScreen(navController = navController)
            }
            composable(route = Screen.LoginScreen.route) {
                LoginScreen(navController = navController)
            }
            composable(route = Screen.GuideScreen.route) {
                GuideScreen(navController = navController, CommonData.itemDataList)
            }
            composable(route = Screen.IndexScreen.route) {
                IndexScreen(navController = navController)
            }
            composable(route = Screen.ChatScreen.route) {
                ChatScreen()
            }
            composable(route = Screen.PermissionsScreen.route) {
                PermissionsScreen()
            }
            composable(route = Screen.NetworkScreen.route) {
                NetworkScreen()
            }
        }
    }
}


/*when (val result = articleViewModel.articleData.value) {
                        is ArticleState.Success -> {
                            IndexScreen(result.articleModel.data.datas)
                        }
                        is ArticleState.Failure -> {

                        }
                        is ArticleState.Loading -> {

                        }
                        is ArticleState.Empty -> {

                        }
                    }*/